//
//  CCYBaseViewController.swift
//  03.微博
//
//  Created by 蔡承毅 on 16/9/17.
//  Copyright © 2016年 IOS. All rights reserved.
//

import UIKit

class CCYBaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    // 登录了没
    var userLogin:Bool = CCYUserAccountVM.shared.isUserLogin
    
    override func loadView() {
        if userLogin {
            self.view = tableview
            
            tableview.delegate = self
            tableview.dataSource = self
        }else{
            setupVisitView()
        }
    }
    
//    private lazy var visitView: CCYVisitView = CCYVisitView()
    
    func setupVisitView(){
        self.view = visitView
        if self is CCYHomeViewController {
            visitView.startRotationAnimation()
        }else if self is CCYDiscoverViewController{
            visitView.setupVisitorInfo(imageName: "visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is CCYMessageViewController{
            visitView.setupVisitorInfo(imageName: "visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is CCYProfileViewController{
            visitView.setupVisitorInfo(imageName: "visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        visitView.delegate = self
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(visitViewRegister))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(visitViewLogin))
    }
    
    // mark: 懒加载
    
    lazy var tableview = UITableView()
    
   private lazy var visitView: CCYVisitView = CCYVisitView()
}

extension CCYBaseViewController :CCYVisitViewDelegate{
    func visitViewLogin() {
        print("visitViewLogin")
        let oauthVC = CCYOauthController()
        
        present(UINavigationController(rootViewController:oauthVC), animated: true, completion: nil)
    }
    func visitViewRegister() {
        print("visitViewRegister")
    }
    
}

extension CCYBaseViewController: UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
}

extension CCYBaseViewController: UITableViewDelegate{
    
}



